<template>
  <!-- table区域-begin -->
  <div>
    <vxe-grid
      style="width: 100%;"
      :height="320"
      size="mini"
      align="center"
      highlight-hover-row
      stripe
      row-key
      row-id="selectedRowKeys"
      column-min-width="150"
      id="id"
      keep-source
      :loading="loading"
      border
      resizable
      showOverflow
      showHeaderOverflow
      :pager-config="tablePage"
      ref="xGrid"
      :row-config="{ useKey: true,keyField: 'id',isCurrent:true,isHover:true}"
      :checkbox-config="{
          checkRowKeys:selectedRowKeys,
          trigger: 'row',
          highlight: true,
          reserve: true}"
      @sort-change="sortChange"
      @checkbox-change="checkboxChangeEvent"
      @checkbox-all="checkboxChangeEvent"
      :data="dataSource"
      :columns="columns"
      @page-change="handlePageChange"
    >
      <template v-slot:top>
        <!-- 操作按钮区域 -->
        <div class="table-operator" v-if="(selectObj.id && !disabled)">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        </div>
      </template>
      <template v-slot:operate="{ row }">
        <a-button v-if="!disabled && row.detailStatus == 0" type="primary" shape="circle" @click="handleEdit(row)" icon="edit"/>
        <a-button v-else type="primary" shape="circle" @click="handleEdit(row)" icon="edit" disabled/>
        <a-divider type="vertical"/>
        <a-dropdown>
          <a-button type="primary" shape="circle" class="ant-dropdown-link" icon="setting"/>
          <a-menu slot="overlay">
            <a-menu-item>
              <a @click="handleDetail(row)">详情</a>
            </a-menu-item>
            <a-menu-item v-if="row.detailStatus == 0">
              <a @click="handleDelete(row.id)" >删除</a>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
      </template>
      <template v-slot:empty>
        <a-empty />
      </template>
    </vxe-grid>
    <wms-pick-detail-modal :selectObj="selectObj" ref="modalForm" @ok="modalFormOk"></wms-pick-detail-modal>
  </div>
  <!-- table区域-end -->

</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { HYListMixin } from '@/mixins/HYListMixin'
  import WmsPickDetailModal from './modules/WmsPickDetailModal'
  import {getAction} from "@api/manage";

  export default {
    name: 'WmsPickDetailList',
    mixins:[HYListMixin, mixinDevice],
    components: {
      WmsPickDetailModal
    },
    data () {
      return {
        description: '出库明细管理页面',
        /* 排序参数 */
        isorter: {
          column: 'pd.createTime',
          order: 'desc',
        },
        selectObj:{},
        disabled: false,
        disableMixinCreated: true,
        // 表头
        columns: [
          {type: "seq", width: 50, align: "center"},//序号
          { title : '行号', align : "center", field : 'lineNo' },
          { title : '状态', align : "center", field : 'detailStatus_dictText' },
          { title : '物料编码', align : "center", field : 'itemCode' },
          { title : '物料名称', align : "center", field : 'itemName' },
          { title : '包装单位', align : "center", field : 'baseUnit_dictText' },
          { title : '需求数量', align : "center", field : 'demonQty' },
          { title : '分配数量', align : "center", field : 'allocateQty' },
          { title : '已拣货数量', align : "center", field : 'pickedQty' },
          { title : '已过账数量', align : "center", field : 'syncQty' },
          { title : '生产日期', align : "center", field : 'lot01' },
          { title : '销售单', align : "center", field : 'lot02' },
          { title : '供应商代码', align : "center", field : 'lot03' },
          { title : 'ERP代码', align : "center", field : 'lot04' },
          { title : '等级', align : "center", field : 'lot05' },
          { title : '档次', align : "center", field : 'lot06' },
          { title : 'SN号', align : "center", field : 'lot07' },
          {title: '创建人', align: "center", field: 'createBy'},
          {title: '创建日期', align: "center", width: 200, field: 'createTime'},
          {title: '更新人', align: "center", field: 'updateBy'},
          {title: '更新日期', align: "center", width: 200, field: 'updateTime'},
          {title: '操作', fixed: 'right', width: 105, slots: {default: 'operate'}}
        ],
        url: {
          list: "/wms/wmsPickDetail/list",
          delete: "/wms/wmsPickDetail/delete",
          deleteBatch: "/wms/wmsPickDetail/deleteBatch",
          exportXlsUrl: "/wms/wmsPickDetail/exportXls",
          importExcelUrl: "wms/wmsPickDetail/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      showDetail(selectObj,disabled) {
        if(!selectObj){
          return;
        }
        this.selectObj = selectObj;
        this.disabled = disabled;
        getAction(this.url.list, {
          pickId: selectObj.id,
          pageNo: this.tablePage.currentPage,
          pageSize: this.tablePage.pageSize
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.tablePage.total = res.result.total;
            this.modalFormOk();
          } else {
            this.dataSource = null;
          }
        })
      },
      loadData() {
        getAction(this.url.list, {
          pickId: this.selectObj.id,
          pageNo: this.tablePage.currentPage,
          pageSize: this.tablePage.pageSize
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.tablePage.total = res.result.total;
          } else {
            this.dataSource = null;
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'pickId',text:'所属拣货单',dictCode:''})
        fieldList.push({type:'int',value:'lineNo',text:'行号',dictCode:''})
        fieldList.push({type:'string',value:'itemId',text:'物料',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>